HTTP Headers
-
HTTP header is a field(key:value) in an HTTP request or response that contains extra information about the request or response.
Header Types
1. Reqeust header
-
HTTP client uses this to provide information about the request context, so that the server can tailor the response.
| Header Name | Content | ||||
|---|---|---|---|---|---|
| Accept request header |
MIME types HTTP client is able to understand.
|
||||
| Authorization request header |
Provide credentials that authenticate a user agent with a server, allowing access to a protected resource
|
||||
| Accept-Language |
natural language and locale that the client prefers
|
||||
| Referer |
Absolute or partial address from which a resource has been requested
|
||||
| Connection |
whether the network connection stays open after the current transaction finishes If the value sent is keep-alive, the connection is persistent and not closed, allowing for subsequent requests to the same server to be done.
|
||||
| Upgrade-Insecure-Requests |
sends a signal to the server expressing the client's preference for an encrypted and authenticated response
|
||||
| Fetch metadata request header |
- Provides additional information about the context from which the request originated. - This allows the server to make decisions about whether a request should be allowed based on where the request came - With this information a server can implement a resource isolation policy - This approach can help mitigate common cross-site web vulnerabilities such as CSRF, Cross-site Script Inclusion('XSSI'), timing attacks, and cross-origin information leaks - Forbidden header name: These headers are prefixed with Sec-, and hence have forbidden header names. A forbidden header name is the name of any HTTP header that cannot be modified programmatically(ie using javascript)
|
||||
| XFF (X-Forwarded-For) Non Mandatory |
This is used for sending original IP header of client when
the connection goes through a proxy or load balancer. Why seeing original IP is important? logging, rate limiting Example: Request from client IP 1.1.1.1 goes through a CDN (2.2.2.2) and then a load balancer. The application server receives the request with the following header: X-Forwarded-For: 1.1.1.1, 2.2.2.2 The leftmost IP (1.1.1.1) is the original client IP |
||||
| XAU (X-Authenticated-User) Non Mandatory |
Similar to XFF, this header contains authenticated username of the end user who made the request. This is used to pass the user identity after initial authentication, preventing the need for re-authentication at every hop. X-Authenticated-User: john.doe, The receiving service reads this header to know which user the request belongs to and applies appropriate access policies. |
2. Response header
3. Representation header
-
describes one particular representation of a resource. Data might be present as XML, JSON, HTML
| Header Name | Meaning | Content |
|---|---|---|
| Content-Type header |
Indicate the original media type(sound file might be labeled audio/ogg, or an image file image/png)
of the resource In requests, (such as POST or PUT), the client tells the server what type of data is actually sent. |
|
| Content-Encoding header |
Tells any encodings that have been applied to the message payload. This lets the recipient know how to decode the representation in order to obtain the original payload format. |
|